package com.example.wlt.personnel_manegement_system.Manager.Person;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import com.example.wlt.personnel_manegement_system.Manager.My.Mycenter;
import com.example.wlt.personnel_manegement_system.Manager.Org.Organization;
import com.example.wlt.personnel_manegement_system.Manager.Org.search;
import com.example.wlt.personnel_manegement_system.Manager.Task.Task;
import com.example.wlt.personnel_manegement_system.R;
import com.example.wlt.personnel_manegement_system.View.ViewPagerIndicator;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by WLT on 2016/4/18.
 */
public class Person extends FragmentActivity implements View.OnClickListener{
    private ImageButton ibtn_org;
    private ImageButton ibtn_task;
    private ImageButton ibtn_mycenter;
    private ViewPager mViewPager;
    private ViewPagerIndicator mIndicator;
    private List<Fragment> mContents = new ArrayList<Fragment>();
    private FragmentPagerAdapter mAdapter;
    private Button btn_back;
    private ImageButton ibtn_search;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.person);
        ibtn_org = (ImageButton) findViewById(R.id.ibtn_org);
        ibtn_task = (ImageButton)findViewById(R.id.ibtn_task);
        ibtn_mycenter = (ImageButton) findViewById(R.id.ibtn_mycenter);
        btn_back=(Button)findViewById(R.id.btn_org_headleft);
        ibtn_search=(ImageButton)findViewById(R.id.ibtn_org_search);
        //返回app首页即部门页面
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent Intent=new Intent(Person.this, Organization.class);
                startActivity(Intent);
                finish();
            }
        });
        //进入搜索页面
        ibtn_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent Intent=new Intent(Person.this, search.class);
                startActivity(Intent);
            }
        });
        //进入部门页面
        ibtn_org.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent Intent=new Intent(Person.this, Organization.class);
                startActivity(Intent);
                finish();
            }
        });
        //进入任务页面
        ibtn_task.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent Intent=new Intent(Person.this,Task.class);
                startActivity(Intent);
                finish();
            }
        });
        //进入个人页面
        ibtn_mycenter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent Intent=new Intent(Person.this,Mycenter.class);
                startActivity(Intent);
                finish();
            }
        });
        initViews();
        initDatas();
        //加载适配器
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                mIndicator.scroll(position, positionOffset);
            }

            @Override
            public void onPageSelected(int position) {
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }
    //初始化Views
    private void initViews(){
        mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
        mIndicator = (ViewPagerIndicator) findViewById(R.id.id_indicator);

    }

    //初始化数据
    private void initDatas() {
        Fragment_managestudio fragmentManagestudio = new Fragment_managestudio();
        Fragment_membermanage fragmentMembermanage = new Fragment_membermanage();
        Fragment_memberstatus fragmentMemberstatus= new Fragment_memberstatus();
        Fragment_mystatus fragmentMystatus = new Fragment_mystatus();
        mContents.add(fragmentMystatus);
        mContents.add(fragmentMemberstatus);
        mContents.add(fragmentMembermanage);
        mContents.add(fragmentManagestudio);
        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mContents.get(position);
            }
            @Override
            public int getCount() {
                return 4;
            }
        };
    }

    @Override
    public void onClick(View v) {

    }
}

